/**
 * 
 */
package com.yidu.menuProject.service;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yidu.menuProject.action.vo.FindFood;
import com.yidu.menuProject.action.vo.UserIndent;
import com.yidu.menuProject.common.Page;
import com.yidu.menuProject.common.Tools;
import com.yidu.menuProject.dao.IndentModelMapper;
import com.yidu.menuProject.dao.InventoryModelMapper;
import com.yidu.menuProject.model.IndentModel;
import com.yidu.menuProject.model.InventoryModel;

/**
 * 类的描述--订单的实现类
 * @author sylval
 * @date 2018年7月13日 上午10:20:47
 * @version 1.0
 */
@Service
public class IndentImpl implements IndentService{
	@Resource
	IndentModelMapper inDao;
	@Resource
	InventoryModelMapper invDao;
	/**
	 * 查询订单的方法
	 */
	public List<UserIndent> findIndent(Page page,String mealId) {
		List<UserIndent> list=inDao.findIndent(page,mealId);
		return list;
	}

	/**
	 * 查询总行数的方法
	 */
	public int findTotalRows() {
		int i=inDao.findTotalRows();
		return i;
	}
	/**
	 * 查询前台订单的方法
	 */
	public List<IndentModel> selectIndent(String userId) {
		List<IndentModel> model=inDao.selectIndent(userId);
		return model;
	}
	/**
	 * 根据订单id查询食物的方法
	 */
	public List<FindFood> findFood(String indId) {
		List<FindFood> foodList=inDao.findFood(indId);
		for (FindFood findFood : foodList) {
			findFood.setFoodAllPrice(findFood.getFoodPrice()*findFood.getFoodNum());
		}
		return foodList;
	}

	/**
	 * 增加订单的方法
	 */
	public void insertSelective(IndentModel record,String foodId,String foodNum) {
		record.setRemarks("快点送达");
		record.setIndDate(new Date());
		inDao.insertSelective(record);
		
		String[] foodIdArr = foodId.split("_");
		String[] foodNumArr = foodNum.split("_");
		System.out.println("jiesuanla");
		System.out.println(foodId+"-------------"+foodNum);
		for (int i = 0; i < foodIdArr.length; i++) {
			InventoryModel inv= new InventoryModel();
			
			inv.setInvId(Tools.getStringRandom(20));
			inv.setIndId(record.getIndId());
			inv.setOptime(new Date());
			inv.setIsva(1);
			inv.setFoodId(foodIdArr[i]);
			inv.setFoodNum(Tools.stringToInt(foodNumArr[i]));
			invDao.insertSelective(inv);
		}
	}
}
